package cn.silver.module.system.domain;

import cn.silver.framework.mybatis.annotation.Table;
import cn.silver.framework.mybatis.annotation.TableField;
import cn.silver.framework.mybatis.domain.BaseEntity;
import cn.silver.framework.mybatis.enums.SearchTypeEnums;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;

import java.io.Serial;
import java.util.List;

/**
 * 用户和岗位关联 sys_user_post
 *
 * @author zhouxiaobo
 */
@Data
@NoArgsConstructor
@Table(name = "sys_dept_post")
@EqualsAndHashCode(callSuper = true)
@Schema(name = "SysDeptPost", description = "部门和岗位关联")
public class SysDeptPost extends BaseEntity {
    @Serial
    private static final long serialVersionUID = 1L;
    /**
     * 归属部门
     */
    @Schema(title = "归属部门")
    @TableField(name = "dept_id", searchType = SearchTypeEnums.EQ)
    private String deptId;

    /**
     * 岗位信息
     */
    @Schema(title = "岗位信息")
    @TableField(name = "post_id", searchType = SearchTypeEnums.EQ)
    private String postId;
    /**
     * 岗位编码
     */
    @Schema(title = "岗位编码")
    @TableField(name = "post_code", searchType = SearchTypeEnums.EQ)
    private String postCode;
    /**
     * 岗位名称
     */
    @Schema(title = "岗位名称")
    @TableField(name = "post_name", searchType = SearchTypeEnums.LIKE)
    private String postName;
    /**
     * 岗位类型
     */
    @Schema(title = "岗位类型")
    @TableField(name = "post_type", searchType = SearchTypeEnums.EQ)
    private String postType;
    @Schema(title = "岗位类型")
    @TableField(name = "status", searchType = SearchTypeEnums.EQ)
    private String status;
    /**
     * 岗位数量
     */
    @Schema(title = "岗位数量")
    @TableField(name = "post_num", searchType = SearchTypeEnums.EQ)
    private Integer postNum;
    /**
     * 是否允许兼职
     */
    @Schema(title = "是否允许兼职")
    @TableField(name = "partable", searchType = SearchTypeEnums.EQ)
    private Boolean partable;
    /**
     * 岗位职责
     */
    @Schema(title = "岗位职责")
    private String remark;
    private transient List<SysPost> posts;

    public SysDeptPost(SysDeptPost entity, SysPost post) {
        this.deptId = entity.getDeptId();
        this.postId = post.getId();
        this.postCode = post.getCode();
        this.postName = post.getName();
        this.postType = post.getType();
        this.status = post.getStatus();
        this.postNum = entity.getPostNum();
        this.partable = entity.getPartable();
        this.remark = entity.getRemark();
    }

    public void reload(SysPost post) {
        this.postId = post.getId();
        this.postCode = post.getCode();
        this.postName = post.getName();
        this.postType = post.getType();
        this.status = post.getStatus();
    }

    @Override
    public void preInsert() {
        super.preInsert();
        if (this.partable == null) {
            this.partable = true;
        }
    }

    @Override
    public void preUpdate() {
        super.preUpdate();
    }

    @Override
    public String toString() {
        return "SysDeptPost{" +
                "deptId='" + deptId + '\'' +
                ", postId='" + postId + '\'' +
                ", postCode='" + postCode + '\'' +
                ", postName='" + postName + '\'' +
                ", postType='" + postType + '\'' +
                ", postNum='" + postNum + '\'' +
                ", partable=" + partable +
                ", remark='" + remark + '\'' +
                '}';
    }


}
